/**
 * 休息信息管理初始化
 */
var DoorRestMessage = {
    id: "DoorRestMessageTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DoorRestMessage.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '休息规则名称', field: 'restName', visible: true, align: 'center', valign: 'middle'},
            {title: '休息日期', field: 'dateTime', visible: true, align: 'center', valign: 'middle',formatter:function(value,row){
                        var fullYear = value.substring(0,10);
                        return fullYear;
            }},
            {title: '星期', field: 'dateTime', visible: true, align: 'center', valign: 'middle',formatter:function(value,row){
                    var d  = new Date(value).getDay()
                    switch (d) {
                        case 1 : x="一";
                        break;
                        case 2 : x="二";
                            break;
                        case 3 : x="三";
                            break;
                        case 4 : x="四";
                            break;
                        case 5 : x="五";
                            break;
                        case 6 : x="六";
                            break;
                        default:x="日"

                    }
                    return x;
                } }

    ];
};

/**
 * 检查是否选中
 */
DoorRestMessage.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DoorRestMessage.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加休息信息
 */
DoorRestMessage.openAddDoorRestMessage = function () {
    var index = layer.open({
        type: 2,
        title: '添加休息信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doorRestMessage/doorRestMessage_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看休息信息详情
 */
DoorRestMessage.openDoorRestMessageDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '休息信息详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doorRestMessage/doorRestMessage_update/' + DoorRestMessage.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除休息信息
 */
DoorRestMessage.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/doorRestMessage/delete", function (data) {
            Feng.success("删除成功!");
            DoorRestMessage.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("doorRestMessageId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询休息信息列表
 */
DoorRestMessage.search = function () {
    var queryData = {};
    queryData['restName'] = $("#restName").val();
    queryData['dateTime'] = $("#dateTime").val();
    queryData['startTime']=$("#startTime").val();
    queryData['endTime']=$("#endTime").val();
    DoorRestMessage.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = DoorRestMessage.initColumn();
    var table = new BSTable(DoorRestMessage.id, "/doorRestMessage/list", defaultColunms);
    table.setPaginationType("client");
    DoorRestMessage.table = table.init();
});
